/**
 * 功能描述
 */

define(function (require, exports, module) {
	var EditGrid = require("editgrid");
	var editGridEvents = require("../handler/editGridEvents");
	var Dialog = require('dialog');
	/*var moment = require("moment");
	var store =require("store");
	var activeUser = store.get("user");	*/
	
    var instance = {
        initComponent: function (params,widget) {
        	var editgrid = new EditGrid({
        		parentNode: ".J-editgrid",
        		model: {
        			allowAdd: false,
        			columns: [{
        				 name : "signUpCharge.signUpRegister.personalInfo.idNumber",
                         label : "身份证号",
        			},{
        				name : "signUpCharge.signUpRegister.personalInfo.name",
                        label : "姓名"
        			},{
        				name : "signUpCharge.signUpRegister.personalInfo.sex.value",
                        label : "性别"
        			},{
        				name : "signUpCharge.signUpRegister.personalInfo.mobilePhone",
                    	label : "手机号"
        			},{
        				name : "signUpCharge.signUpRegister.travelContract.productRule.product.name",
                    	label : "权证名称"
        			},{
        				name : "signUpCharge.signUpRegister.travelContract.memberCertificates",
                    	label : "权证号"
        			},{
        				name : "signUpCharge.payable",
                    	label : "应退金额",
                    	format:function(val){
							return Number(val).toFixed(2);
                    	}
        			},{
        				name : "refund",
                    	label : "实退金额",
                    	format:function(value,row){
                    		if(row.refund){
                    			return Number(value).toFixed(2);
                    		}else{
                    			value=0;
                    			return Number(value).toFixed(2);
                    		}
						},
						editor : {
							type:"text",
							onEdit:function(editor,rowIndex,rowData){
								editor.setValue(rowData.refund);
							},
							onChange : function(plugin,index,rowData){
								
								var income = plugin.getValue();
								var reg = /-?(0|[1-9]\d*)(\.\d+)?/;
								
								if(reg.test(income)){
									rowData.refund = Number(plugin.getValue()).toFixed(2);
									editgrid.update(index, rowData);
									editGridEvents.setTotal(editgrid, widget);
								}else{
									Dialog.alert({
										title : "提示",
										content : "请输入正确的价格！",
									});
									return;
								}
							}
						}
        			},{
        				name : "operator.name",
                    	label : "经办人",
                    	/*format:function(value,row){
                    		if(row.operator){
                    			return value;
                    		}else{
                    			return activeUser.name;
                    		}
						},*/
        			},{
        				name : "refundDate",
                    	label : "退费日期",
                    	format: "date",
                    	/*format:function(value,row){
                    		if(row.refundDate){
                    			return value;
                    		}else{
                    			return moment(new Date()).format("yyyy-MM-dd");
                    		}
						},*/
        			}]
        		}
        	});
        	 widget.set("editgrid", editgrid);
        }
    };
    module.exports = instance;
});
